package bzqn.com.rongcloudsdk;

import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import bzqn.com.rongcloudsdk.utils.DialogUtils;
import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;

public class ChatActivity extends BaseActivity {

    private Toolbar mToolbar;
    private String targetId;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        Uri uri = getIntent().getData();
        String title = uri.getQueryParameter("title");
        targetId = uri.getQueryParameter("targetId");
        mToolbar.setTitle(title);
        setSupportActionBar(mToolbar);
        mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.jubao:
                        jubao();
                        break;
                    case R.id.black:
                     addUserToBalcklist();
                        break;
                    default:
                        break;
                }
                return true;
            }
        });
    }

    public static void startChat(Context context, String uid, String title){
        RongIM.getInstance().setMessageAttachedUserInfo(true);
        RongIM.getInstance().startConversation(context, Conversation.ConversationType.PRIVATE,uid,title);
    }
    private void jubao(){
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
        builder.setItems(new String[]{"垃圾广告,推销","侮辱性语言","色情","其他"}, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                DialogUtils.showToast("举报用户!");
                switch (which){
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                }
            }
        });
        builder.show();
    }
    private void addUserToBalcklist(){

        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
        builder.setTitle("提示");
        builder.setMessage("拉黑后,TA将无法对您评论,聊天!");
        builder.setNegativeButton("取消",null);
        builder.setPositiveButton("确认拉黑", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                RongIM.getInstance().addToBlacklist(targetId, new RongIMClient.OperationCallback() {
                    @Override
                    public void onSuccess() {
                        finish();
                    }

                    @Override
                    public void onError(RongIMClient.ErrorCode errorCode) {
                        DialogUtils.showNetWorkError();
                    }
                });
            }
        });
        builder.show();

    }
}
